import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'index',
    component: () => import('@/pages/index/index.vue'),
    meta: {
      title: '首页'
    }
  },
  {
    path: '/custom',
    name: 'custom',
    component: () => import('@/pages/custom/index.vue'),
    meta: {
      title: '自定义'
    }
  },
  {
    path: '/category',
    name: 'category',
    component: () => import('@/pages/category/index.vue'),
    meta: {
      title: '分类'
    }
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/pages/search/index.vue'),
    meta: {
      title: '搜索'
    }
  },
  {
    path: '/shop',
    name: 'shop',
    component: () => import('@/pages/shop/index.vue'),
    meta: {
      title: '店铺'
    }
  },
  {
    path: '/shop/detail',
    name: 'shop-detail',
    component: () => import('@/pages/shop/detail/index.vue'),
    meta: {
      title: '店铺详情'
    }
  },
  {
    path: '/goods',
    name: 'goods',
    component: () => import('@/pages/goods/index.vue'),
    meta: {
      title: '商品详情'
    }
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import('@/pages/cart/index.vue'),
    meta: {
      title: '购物车'
    }
  },
  {
    path: '/buy',
    name: 'buy',
    component: () => import('@/pages/buy/index.vue'),
    meta: {
      title: '确认订单'
    }
  },
  {
    path: '/buy/pay-type',
    name: 'pay-type',
    component: () => import('@/pages/buy/pay-type/index.vue'),
    meta: {
      title: '确认订单-付款'
    }
  },
  {
    path: '/buy/pay-scan',
    name: 'pay-scan',
    component: () => import('@/pages/buy/pay-scan/index.vue'),
    meta: {
      title: '确认订单-扫码'
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/pages/login/index.vue'),
    meta: {
      title: '登录'
    }
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/pages/register/index.vue'),
    meta: {
      title: '注册'
    }
  },
  {
    path: '/notice',
    name: 'notice',
    component: () => import('@/pages/notice/index.vue'),
    meta: {
      title: '公告'
    }
  },
  {
    path: '/notice/detail',
    name: 'notice/detail',
    component: () => import('@/pages/notice/detail/index.vue'),
    meta: {
      title: '公告详情'
    }
  },
  {
    path: '/center',
    name: 'center',
    component: () => import('@/pages/center/index.vue'),
    children: [
      {
        path: 'order',
        name: 'order-management',
        component: () => import('@/pages/center/order/index.vue'),
        redirect: '/center/order/my-order',
        children: [
          {
            path: 'my-order',
            name: 'my-order',
            component: () => import('@/pages/center/order/my-order/index.vue'),
            meta: {
              title: '我的订单'
            }
          },
          {
            path: 'platform-order',
            name: 'platform-order',
            component: () => import('@/pages/center/order/platform-order/index.vue'),
            meta: {
              title: '平台订单'
            }
          }
        ],
        meta: {
          title: '订单管理'
        }
      },
      {
        path: '/center/order/platform-order/order-detail/:status',
        name: 'order-detail',
        component: () => import('@/pages/center/order/platform-order/order-detail/index.vue'),
        meta: {
          title: '平台订单详情'
        }
      },
      {
        path: '/center/order/my-order/my-order-detail/',
        name: 'my-order-detail',
        component: () => import('@/pages/center/order/my-order/my-order-detail/index.vue'),
        meta: {
          title: '我的订单详情'
        }
      },
      {
        path: 'unpaid-order',
        name: 'unpaid-order',
        component: () => import('@/pages/center/unpaid-order/index.vue'),
        meta: { title: '待付款订单' },
        redirect: '/center/unpaid-order/my-unpaid-order',
        children: [
          {
            path: 'platform-unpaid-order',
            name: 'platform-unpaid-order',
            component: () => import('@/pages/center/unpaid-order/platform-unpaid-order/index.vue'),
            meta: { title: '平台待支付订单' }
          },
          {
            path: 'my-unpaid-order',
            name: 'my-unpaid-order',
            component: () => import('@/pages/center/unpaid-order/my-unpaid-order/index.vue'),
            meta: { title: '待支付订单' }
          }
        ]
      },
      {
        path: 'save',
        name: 'save',
        component: () => import('@/pages/center/save/index.vue'),
        meta: {
          title: '安全中心'
        }
      },
      {
        path: 'address',
        name: 'address',
        component: () => import('@/pages/center/address/index.vue'),
        meta: {
          title: '收货地址'
        }
      },
      {
        path: 'store-management',
        name: 'store-management',
        component: () => import('@/pages/center/store-management/index.vue'),
        meta: {
          title: '店铺管理'
        }
      },
      {
        path: 'platform-goods',
        name: 'platform-goods',
        component: () => import('@/pages/center/platform-goods/index.vue'),
        meta: {
          title: '平台商品'
        }
      },
      {
        path: 'after-sales-order',
        name: 'after-sales-order',
        component: () => import('@/pages/center/after-sales-order/index.vue'),
        meta: {
          title: '售后订单'
        }
      },
      {
        path: 'after-sales-detail',
        name: 'after-sales-detail',
        component: () => import('@/pages/center/after-sales-order/detail/index.vue'),
        meta: {
          title: '售后详情'
        }
      },
      {
        path: 'apply-after-sales',
        name: 'apply-after-sales',
        component: () => import('@/pages/center/apply-after-sales/index.vue'),
        meta: {
          title: '申请售后'
        }
      },
      {
        path: '',
        redirect: '/center/order/my-order'
      }
    ],
    meta: {
      title: '会员中心'
    }
  },
  {
    path: '/:catchAll(.*)',
    name: '404',
    component: () => import('@/pages/404/404.vue'),
    meta: {
      title: '页面不存在',
      index: '/:catchAll(.*)'
    }
  },
  {
    path: '/error/illegal-user',
    name: 'illegal-user',
    component: () => import('@/pages/error/illegal-user/index.vue'),
    meta: {
      title: '非法用户'
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  scrollBehavior() {
    return new Promise(resolve => {
      resolve({ left: 0, top: 0 })
    })
  },
  routes
})

export default router
